#include "viml/string_intern_pool.h"
#include <iostream>
#include <algorithm>

namespace viml {

// GlobalSimpleStringInternPool实现
std::unique_ptr<SimpleStringInternPool> GlobalSimpleStringInternPool::instance_;
std::mutex GlobalSimpleStringInternPool::instance_mutex_;
bool GlobalSimpleStringInternPool::initialized_ = false;

SimpleStringInternPool& GlobalSimpleStringInternPool::get_instance() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (!instance_) {
        instance_ = std::make_unique<SimpleStringInternPool>();
        initialized_ = true;
    }
    return *instance_;
}

void GlobalSimpleStringInternPool::initialize() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (!instance_) {
        instance_ = std::make_unique<SimpleStringInternPool>();
        initialized_ = true;
    }
}

void GlobalSimpleStringInternPool::shutdown() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (instance_) {
        instance_->clear();
        instance_.reset();
        initialized_ = false;
    }
}

bool GlobalSimpleStringInternPool::is_initialized() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    return initialized_;
}

} // namespace viml